<?php

require_once 'Zend/Cache.php';
require_once 'Zend/Http/Client.php';
require_once 'Zend/Feed/Reader.php';

$frontendOptions = array(
   'lifetime' => 86400,
   'automatic_serialization' => true
);
$backendOptions = array('cache_dir' => './cache/');
$cache = Zend_Cache::factory(
    'Core', 'File', $frontendOptions, $backendOptions
);

// Set the configuration parameters
$proxy = array(
    'adapter'    => 'Zend_Http_Client_Adapter_Proxy',
    'proxy_host' => 'proxysg.uwe.ac.uk',
    'proxy_port' => 80
);

$client = new Zend_Http_Client();

Zend_Feed_Reader::setHttpClient($client, $proxy);
Zend_Feed_Reader::setCache($cache);
Zend_Feed_Reader::useHttpConditionalGet();

function loadFeed ($url) {
	try {
		$feed = Zend_Feed_Reader::import($url);
	} catch (Zend_Feed_Exception $e) {
		// feed import failed
		return null;
}
	return $feed;
}

function get_feed_array ($url) {

	$feed = loadFeed ($url);
	
	$blog = array(
    	'title'        => $feed->getTitle(),
    	'link'         => $feed->getLink(),
    	'dateModified' => $feed->getDateModified(),
    	'description'  => $feed->getDescription(),
		'author'	   => $feed->getAuthor(0),
    	'language'     => $feed->getLanguage(),
    	'entries'      => array(),
	);

	foreach ($feed as $entry) {
    	$edata = array(
        	'title'        => $entry->getTitle(),
			'id'		   => $entry->getId(),
        	'description'  => $entry->getDescription(),
        	'dateModified' => $entry->getDateModified(),
        	'author'       => $entry->getAuthor(),
        	'link'         => $entry->getLink(),
        	'content'      => $entry->getContent()
    	);
    	$blog['entries'][] = $edata;
	}
	
	return $blog;

}

?>